<template>
  <div class="policy_holder">
    <div class="name">
      <span></span>{{config.attrName}}
    </div>
    <div class="title_example" @click="show=true">
      <!-- <img src="@/assets/img/tips.png" alt=""> -->
      查看示例
    </div>
    <div class="van-image-preview" style="z-index: 2004;" @click="show = false" v-show="show">
      <van-swipe :width="width" indicator-color="white">
        <van-swipe-item v-for="(image, index) in images" :key="index">
          <span>{{image.name}}</span>
          <img v-lazy="image.url" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="van-overlay van-image-preview__overlay" @click="show = false" v-show="show" style="z-index: 2003;"></div>

  </div>
</template>
<script>
import publicfunc from "@/assets/js/publicFunc.js";
export default {
  name: "title_example",
  props: {
    config: {
      type: Object,
      required: true
    },
    parentIndex: Number,
    itemIndex: Number
  },
  // props: ['detail'],
  data() {
    return {
      Data: {},
      show: false,
      images: [],
      width: 0
    };
  },
  created() {
    this.width = document.body.clientWidth;
    if (this.config && (!this.config.imgList || !this.config.imgList.length)) {
      this.getApollo();
    } else {
      this.images = this.config.imgList;
    }
  },
  methods: {
    getApollo() {
      let params = {
        spaceName: "JSONImages",
        key: this.config.attrKeyName
      };
      let that = this,
        array;
      this.$api.handleGet("/api/v1/QueryApolloSettings", params, result => {
        if (result) {
          if (typeof result == "string") {
            array = result.replace(/\s*/g, "").replace(",]", "]");
            that.images = JSON.parse(array).images;
          } else {
            that.images = result.images;
          }
          that.config.imgList = that.images;
        }
      });
    },
    imagePreview() {}
  }
};
</script>
<style lang="less">
.policy_holder {
  height: 1.093333rem;
  background: #fafafa;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.533333rem;
  box-shadow: inset 0px 5px 15px -15px #333, inset 0px -5px 15px -15px #333;
  .name,
  .title_example {
    height: 100%;
    width: 50%;
    display: flex;
    flex-direction: row;
    align-items: center;
    font-size: 0.4rem;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    color: rgba(110, 154, 251, 1);
    span {
      width: 0.08rem;
      height: 0.32rem;
      background: rgba(43, 103, 254, 1);
      border-radius: 0.053333rem;
      margin-right: 0.213333rem;
    }
  }
  .title_example {
    width: 30%;
    justify-content: flex-end;
    font-size: 0.32rem;
    font-family: PingFangSC-Regular;
    color: rgba(42, 103, 255, 1);
    // img {
    //   width: 0.373333rem;
    //   height: 0.373333rem;
    // }
  }
}
</style>

